﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace hse_2013_test_dima_sasha
{
    public partial class Form5 : Form
    {
        public Form5()
        {
            InitializeComponent();
        }

        private List<TextBox> TextBoxes = new List<TextBox>();
        private bool correctEnter = true;

        private void Form5_Load(object sender, EventArgs e)
        {
            TextBoxes.Add(textBox2);
            TextBoxes.Add(textBox3);
            TextBoxes.Add(textBox4);
            TextBoxes.Add(textBox5);
            TextBoxes.Add(textBox6);
            if (Data.SubjectID == 1)
            {
                label2.Text = "Первая часть предложения";
                label3.Text = "Вторая часть предложения";
                label3.Visible = true;
                button2.Hide();
            }
            else
            {
                label2.Text = "Вопрос";
                label3.Visible = false;
                textBox2.Visible = false;
                button1.Hide();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            foreach (var textBox in TextBoxes)
            {
                if (textBox.Text == String.Empty)
                    correctEnter = false;
            }
            if (correctEnter)
            {
                string file = ".../.../English.txt";
                var sw = new StreamWriter(file, true, Encoding.Default);
                sw.WriteLine(textBox1.Text + "....." + textBox2.Text);
                sw.WriteLine(textBox3.Text);
                sw.WriteLine(textBox4.Text);
                sw.WriteLine(textBox5.Text);
                sw.WriteLine(textBox6.Text);
                sw.Close();
                MessageBox.Show("Вопрос добавлен!", "Успех, товарищи!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                FormClear();
            }
            else
            {
                MessageBox.Show("Некорректный ввод!");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            foreach (var textBox in TextBoxes)
            {
                if (textBox.Text == String.Empty)
                    correctEnter = false;
            }
            if (correctEnter)
            {
                string file = ".../.../Economics.txt";
                var sw = new StreamWriter(file, true, Encoding.Default);
                sw.WriteLine(textBox1.Text);
                sw.WriteLine("4");
                sw.WriteLine(textBox3.Text);
                sw.WriteLine(textBox4.Text);
                sw.WriteLine(textBox5.Text);
                sw.WriteLine(textBox6.Text);
                sw.Close();
                MessageBox.Show("Вопрос добавлен!", "Успех, товарищи!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                FormClear();
            }
            else
            {
                MessageBox.Show("Некорректный ввод!");
            }
        }

        private void FormClear()
        {
            foreach (TextBox textBox in TextBoxes)
            {
                textBox.Clear();
            }
        }
    }
}
